<?php
require $_SERVER['DOCUMENT_ROOT'].'/../_core/common.php';


$msg = array();

//权限验证
if( Role::init() == false ){
	$msg['error'] = false;
	$msg['string'] = '权限不足！';
	$myjson = json_encode($msg); 
	echo $myjson; 
	exit;
}

$db = new DB('star');

$time = time();
$uid = Sessions::get('uid');
$ip = IP::get();
$views = rand(100,200);
$news_images = '/n_upload/handle/20130608/64ac4a858885861d7fce67eeb3c7056c-1370670701.jpg';
$star_images = '/n_upload/handle/20130428/ec0c64df375ed72435b7974acfff0125-1367139431.jpg';

$star_sql = 'select title_id from star order by title_id desc limit 1';
$star_rs = $db->query($star_sql)->getOne();
$new_title_id = $star_rs['title_id']+1;

$static_url = 'http://star.zgqw.com/v/'.$new_title_id;

$star_data = array('title'=>'空白档-'.$new_title_id,
					'title_history_id'=>1,
					'static_url'=>$static_url,
					'views'=>$views,
					'index_thumb'=>$news_images,
					'thumb'=>$star_images,
					'ip'=>$ip,
					'is_empty'=>1,
					'created'=>$time,
					'updated'=>$time,
					'create_uid'=>$uid,
					'edit_uid'=>$uid,);
$db->table('star')->insert($star_data)->run();//插入
$insert_id = $db->table('star')->getId();

$star_history_data = array('history_id'=>1,
					'title_id'=>$new_title_id,
					'title'=>'空白档-'.$new_title_id,
					'static_url'=>$static_url,
					'index_thumb'=>$news_images,
					'views'=>$views,
					'thumb'=>$star_images,
					'created'=>$time,
					'create_uid'=>$uid,);
$db->table('star_history')->insert($star_history_data)->run();//插入

$star_track_data = array('track_id'=>1,
					'title_history_id'=>1,
					'title_id'=>$new_title_id,
					'changes'=>'0-1',
					'created'=>$time,
					'create_uid'=>$uid,);
$db->table('star_track')->insert($star_track_data)->run();//插入

if( $insert_id == $new_title_id ){
	$msg['error'] = true;
	$msg['string'] = '成功创建《空白档-'.$new_title_id.'》!';
}else{
	$msg['error'] = false;
	$msg['string'] = '创建失败，请重试！';
}

$myjson = json_encode($msg); 
echo $myjson; 
exit;